@extends('admin.master')

@section('title','管理员列表')

@section('css')
    <!--dynamic table-->
    <link href="{{asset('admin/assets/js/advanced-datatable/css/demo_page.css')}}" rel="stylesheet" />
    <link href="{{asset('admin/assets/js/advanced-datatable/css/demo_table.css" rel="stylesheet')}}" />
    <link rel="stylesheet" href="{{asset('admin/assets/js/data-tables/DT_bootstrap.css')}}" />
@endsection

@section('content')
    <!-- page heading start-->
    <div class="page-heading">
        <ul class="breadcrumb">
            <li>
                <a href="{{ url('back/index') }}">后台首页</a>
            </li>
            <li>
                <a href="{{ url('back/category/form') }}">添加父类</a>
            </li>
            <li class="active">管理员列表</li>
        </ul>
    </div>
    <!-- page heading end-->

    <!--body wrapper start-->
    <div class="wrapper">
        @if( session()->get('msg'))
            <div class="alert alert-success alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                <strong>恭喜你</strong> {{  session()->get('msg') }}
            </div>
        @endif
        @if(count($errors)>0 || session()->get('error'))
            <div class="alert alert-danger alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                <strong>错误</strong>
                @if(session()->get('error'))
                    {{ session()->get('error') }}
                @endif
                @if(count($errors)>0)
                    @foreach ($errors->all() as $error)
                        {{ $error }}
                    @endforeach
                @endif
            </div>
        @endif
        <div class="row">
            <div class="col-sm-12">
                <section class="panel">
                    <header class="panel-heading">
                        <span class="tools">
                            <span class="tools pull-left">
                                {!! Form::open(['url' => 'back/category/add','method' => 'post','class' => 'form']) !!}
                                {{ csrf_field() }}
                                    <span class="tools pull-left"><input type="text" class="form-control" placeholder="Search" name="keywords" value="{{$request['keywords'] or ''}}"/></span>
                                    <span class="tools pull-left"><input type="submit" class="form-control" value="搜索"/></span>
                                {!! Form::close() !!}
                            </span>

                        </span>
                    </header>
                    <div class="panel-body">
                        <div class="adv-table">
                            <div class="table-responsive">
                                <table  class="table table-striped">
                                    <tr>
                                        {!! Form::open(['url' => 'back/category/add','method' => 'post']) !!}
                                        {{ csrf_field() }}
                                        <td class="text-center">{!! Form::button('<i class="fa fa-times"></i>'.'添加顶级分类'.'<i class="fa fa-times"></i>',['class' => 'form-control']) !!}</td>
                                        <td class="text-center">{!! Form::text('title','',['placeholder'=> '请输入要添加的顶级类目名称','class' => 'form-control']) !!}</td>
                                        <td class="text-center">{!! Form::button('<i class="fa fa-check"></i>',['class' => 'btn btn-lg btn-login btn-block','type' => 'submit']) !!}</td>
                                        <td class="text-center">{!! Form::button('<i class="fa fa-times"></i>',['class' => 'btn btn-lg btn-login btn-block','type' => 'reset']) !!}</td>
                                        {!! Form::close() !!}
                                    </tr>
                                </table>
                            </div>
                        </div>

                    <div class="table-responsive">
                            <table  class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th class="text-center">分类编号</th>
                                        <th class="text-center">分类名称</th>
                                        <th class="text-center">修改分类</th>
                                        <th class="text-center">父类id</th>
                                        <th class="text-center">分类路径</th>
                                        <th class="text-center">添加子类</th>
                                        <th class="text-center">删除分类</th>
                                    </tr>
                                </thead>
                                <tbody>
                                @foreach($data as $key1 => $value)
                                    <input type="hidden" value="{!! $count = substr_count($value->path,',') !!}"/>
                                    <tr>
                                        <td class="text-center">{{$value->id}}</td>
                                        <td class="text-center">{!! $title = str_repeat('--|',$count).$value->title !!}</td>
                                        <td class="text-center"><a href="javascript:;"><i class="fa fa-pencil" data-toggle="modal" data-target="#myModal2" data-id="{{$value->id}}" data-title="{{$value->title}}"></i></a></td>
                                        <td class="text-center">{{$value->parentid}}</td>
                                        <td class="text-center">{{$value->path}}</td>
                                        <td class="text-center"><a href="javascript:;"><i class="fa fa-plus" data-toggle="modal" data-target="#myModal"  data-id="{{$value->id}}"></i></a></td>
                                        <td class="text-center"><a href="delete/{{ $value->id }}"><i class="fa fa-times"></i></a></td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        <div class="row-fluid">
                            <div class="dataTables_paginate paging_bootstrap pagination">{!! $data->appends($request)->render() !!}</div>
                        </div>
                    </div>


                        <!-- Modal -->

                        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            {!! Form::open(['url' => '','method' => 'post','id' => 'form-fix']) !!}
                            {{ csrf_field() }}
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                        <h4 class="modal-title" id="myModalLabel">添加子类</h4>
                                    </div>
                                    <div class="modal-body">
                                       <input  type="text" value="" name="title" class="form-control"/>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-default">确认</button>
                                        <button type="reset" class="btn btn-primary">重置</button>
                                    </div>
                                </div><!-- /.modal-content -->
                            </div><!-- /.modal-dialog -->
                            {!! Form::close() !!}
                        </div><!-- /.modal -->

                        <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            {!! Form::open(['url' => '','method' => 'post','id' => 'form-add']) !!}
                            {{ csrf_field() }}
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                        <h4 class="modal-title" id="myModalLabel">修改</h4>
                                    </div>
                                    <div class="modal-body">
                                        <input  type="text" value="" name="title" id="title" class="form-control"/>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-default">确认</button>
                                        <button type="reset" class="btn btn-primary">重置</button>
                                    </div>
                                </div><!-- /.modal-content -->
                            </div><!-- /.modal-dialog -->
                            {!! Form::close() !!}
                        </div><!-- /.modal -->


                        </div>
                </section>
            </div>
        </div>
    </div>
    <!--body wrapper end-->
    <!--footer section start-->
    <footer>
        2014 &copy; AdminEx by <a href="http://www.bookfrank.cn/" target="_blank">源码之家</a>
    </footer>
    <!--footer section end-->
@endsection

@section('js')
    <!--dynamic table-->
    <script type="text/javascript" language="javascript" src="{{asset('admin/assets/js/advanced-datatable/js/jquery.dataTables.js')}}"></script>
    <script type="text/javascript" src="{{asset('admin/assets/js/data-tables/DT_bootstrap.js')}}"></script>
    <!--dynamic table initialization -->
    <script src="{{asset('admin/assets/js/dynamic_table_init.js')}}"></script>
    <script type="text/javascript">
        var modal = $("#myModal");
        modal.on("show.bs.modal", function(e) {
            // 这里的btn就是触发元素，
            var i = $(e.relatedTarget);
            console.log($(e.relatedTarget).data());
//            var form = $('#form-fix');
//            form.attr('action','http://wangliquan.com/back/category/add/'+i.data("id"));
//            alert(form.attr('action'));
        });

        var modal2 = $("#myModal2");
        modal2.on("show.bs.modal", function(e) {
            // 这里的btn就是触发元素，
            var i = $(e.relatedTarget);
                console.log($(e.relatedTarget).data());
//            var id = i.data("id");
            var input = $('#title');
            input.attr('value',$(e.relatedTarget).data('title'));
//            var form = $('#form-add');
//            form.attr('action','http://wangliquan.com/back/category/edit/'+id);
//            alert(form.attr('action'));
        });
    </script>
@endsection